package com.ddyx.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.ddyx.entity.wxSubInfo;
import com.ddyx.mapper.wxSubInfoMapper;
import com.ddyx.service.IWxSubInfoService;
import com.ddyx.util.DateUtil;
import com.ddyx.util.Page;
import com.ddyx.util.PageUtil;
import com.ddyx.util.RequestForm;
import com.ddyx.util.ResponseForm;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
public class WxSubInfoServiceImpl implements IWxSubInfoService {

	@Resource
	wxSubInfoMapper subInfoMapper;

	@SuppressWarnings("unchecked")
	@Override
	public ResponseForm selectSubInfo(RequestForm param) {
		ResponseForm result = new ResponseForm();
		Map<String, Object> paramMap = (Map<String, Object>) param.getData();
		try {
			List<wxSubInfo> subList = subInfoMapper.selectSubInfo(PageUtil.isPage(paramMap));
			result.setData(subList);
		} catch (Exception e) {
			result.setStatus(false);
			result.setMessage("查询商品详情错误");
			log.error(e + "查询商品详情错误");
		}
		return result;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public ResponseForm selectSubInfoByWxUid(RequestForm param) {
		ResponseForm result = new ResponseForm();
		Map<String, Object> paramMap = (Map<String, Object>) param.getData();
		try {
			List<wxSubInfo> subList = subInfoMapper.selectSubInfoByWxUid(Page.parse(paramMap));
			result.setData(subList);
			int total  = subInfoMapper.selectSubInfoCount(paramMap);
			result.setTotal(total);
		} catch (Exception e) {
			result.setStatus(false);
			result.setMessage("查询商品详情错误");
			log.error(e + "查询商品详情错误");
		}
		return result;
	}

	@SuppressWarnings("unchecked")
	@Override
	public ResponseForm insertSubInfo(RequestForm param) {
		ResponseForm result = new ResponseForm();
		Map<String, Object> paramMap = (Map<String, Object>) param.getData();
		try {
//			paramMap.put("createTime", DateUtil.format_ymd_hms.format(new Date()));// 时间
			int index = subInfoMapper.insertSubInfo(paramMap);
			if (index < 0) {
				result.setStatus(false);
				result.setMessage("加入预约列表失败");
			}
		} catch (Exception e) {
			result.setStatus(false);
			result.setMessage("加入预约列表错误");
			log.error(e + "加入预约列表错误");
		}
		return result;
	}
	@SuppressWarnings("unchecked")
	@Override
	public ResponseForm cancelSubInfo(RequestForm param) {
		ResponseForm result = new ResponseForm();
		Map<String, Object> paramMap = (Map<String, Object>) param.getData();
		paramMap.put("createTime", DateUtil.format_ymd_hms.format(new Date()));// 当前时间
		try {
			int index = subInfoMapper.cancelSubInfo(paramMap);
			if (index < 0) {
				result.setStatus(false);
				result.setMessage("取消商品预约失败");
			}
		} catch (Exception e) {
			result.setStatus(false);
			result.setMessage("取消商品预约错误");
			log.error(e + "取消商品预约错误");
		}
		return result;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public ResponseForm updateSubInfo(RequestForm param) {
		ResponseForm result = new ResponseForm();
		Map<String, Object> paramMap = (Map<String, Object>) param.getData();
		try {
			int index = subInfoMapper.updateSubInfo(paramMap);
			if (index < 0) {
				result.setStatus(false);
				result.setMessage("修改商品预约信息失败");
			}
		} catch (Exception e) {
			result.setStatus(false);
			result.setMessage("修改商品预约信息错误");
			log.error(e + "修改商品预约信息错误");
		}
		return result;
	}

	
}
